package cn.wolfcode.luowowo.mgrsite.controller;

import cn.wolfcode.luowowo.article.domain.Region;
import cn.wolfcode.luowowo.article.service.IDestinationService;
import cn.wolfcode.luowowo.article.service.IRegionService;
import cn.wolfcode.luowowo.common.query.QueryObject;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 区域的控制器
 */
@Controller
@RequestMapping("/region")
public class RegionController {

    @Reference
    private IRegionService regionService;

    @Reference
    private IDestinationService destinationService;

    /**
     * 区域管理的列表界面
     * @param qo
     * @param model
     * @return
     */
    @RequestMapping("/list")
    public String list(@ModelAttribute("qo") QueryObject qo, Model model) {
        model.addAttribute("pageInfo", regionService.query(qo));
        return "region/list";
    }

    /**
     * 保存更新(编辑操作)
     * 资源：  /region/saveOrUpdate
     * 参数：  region
     * 返回：
     * @return
     */
    @ResponseBody
    @RequestMapping("/saveOrUpdate")
    public Object saveOrUpdate(Region entity) {
        return destinationService.saveOrUpdate(entity);
    }

    /**
     * 区域管理编辑和添加(查询所有目的地)
     * 资源：  /region/listDests
     * 参数：  无
     * 返回：  [    {      id: xxx      name: xxx    },    { ... },    ...  ]
     * @return
     */
    @ResponseBody
    @RequestMapping("/listDests")
    public Object listDests() {
        return destinationService.listDests();
    }

}
